\section{Source/File.c}


\begin{footnotesize}\begin{alltt}
00001 \textcolor{preprocessor}{#include "File.h"}
00002 
00003 \textcolor{keywordtype}{boolean} FileExists(\textcolor{keywordtype}{char} *Filename)
00004 \{
00005     FILE *File = fopen(Filename, \textcolor{stringliteral}{"r"});
00006     \textcolor{keywordflow}{if}(File == NULL)
00007         \textcolor{keywordflow}{return} False;
00008     fclose(File);
00009     \textcolor{keywordflow}{return} True;
00010 \}
00011 
00012 \textcolor{keywordtype}{boolean} DirectoryExists(\textcolor{keywordtype}{char} *DirectoryName)
00013 \{
00014     \textcolor{keyword}{struct }stat S;
00015     \textcolor{keywordflow}{if}(stat(DirectoryName, &S)==0)
00016         \textcolor{keywordflow}{return} True;
00017     \textcolor{keywordflow}{return} False;
00018 \}
00019 
00020 \textcolor{keywordtype}{int} FileModifiedTime(\textcolor{keywordtype}{char} *Filename)
00021 \{
00022     \textcolor{keyword}{struct }stat Info;
00023     \textcolor{keywordflow}{if}(stat(Filename, &Info)!=0)
00024         \textcolor{keywordflow}{return} -1;
00025     \textcolor{keywordflow}{return} Info.st\_mtime;
00026 \}
00027 
00028 \textcolor{keywordtype}{int} FileSize(\textcolor{keywordtype}{char} *Filename)
00029 \{
00030     \textcolor{keyword}{struct }stat Info;
00031     \textcolor{keywordflow}{if}(stat(Filename, &Info)!=0)
00032         \textcolor{keywordflow}{return} -1;
00033     \textcolor{keywordflow}{return} Info.st\_size;
00034 \}
00035 
00036 \textcolor{keywordtype}{int} GetEntireFile(\textcolor{keywordtype}{char} *Filename, \textcolor{keywordtype}{char} *Buffer)
00037 \{
00038     \textcolor{keywordtype}{char} C;
00039     \textcolor{keywordtype}{int} Index = 0;
00040     FILE *FileHandle = fopen(Filename, \textcolor{stringliteral}{"r"});
00041     \textcolor{keywordflow}{if}(FileHandle == NULL)
00042         \textcolor{keywordflow}{return} -1;
00043     \textcolor{keywordflow}{while}(!feof(FileHandle) && !ferror(FileHandle))
00044     \{
00045         \textcolor{comment}{/* char Tmp[100];}
00046 \textcolor{comment}{             fgets(Tmp, 100, FileHandle);*/}
00047         C = getc(FileHandle);
00048         Buffer[Index++] = C;
00049     \}
00050     \textcolor{keywordflow}{if}(ferror(FileHandle))
00051         \textcolor{keywordflow}{return} -1;
00052     Buffer[Index-1] = \textcolor{charliteral}{'\(\backslash\)0'};
00053     \textcolor{keywordflow}{return} Index;
00054 \}
00055 
00056 \textcolor{keywordtype}{int} SetEntireFile(\textcolor{keywordtype}{char} *Name, \textcolor{keywordtype}{char} *Data, \textcolor{keywordtype}{int} Size)
00057 \{
00058     FILE *FileHandle = fopen(Name, \textcolor{stringliteral}{"w"});
00059     \textcolor{keywordflow}{if}(FileHandle == NULL)
00060         \textcolor{keywordflow}{return} -1;
00061     \textcolor{keywordtype}{int} Written = fwrite(Data, \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}), Size, FileHandle);
00062     \textcolor{keywordflow}{if}(Written != Size)
00063         \textcolor{keywordflow}{return} -1;
00064     \textcolor{keywordflow}{return} 0;
00065 \}
00066 
00067 \textcolor{preprocessor}{#ifdef TEST}
00068 \textcolor{preprocessor}{}\textcolor{keywordtype}{int} main()
00069 \{
00070     SetEntireFile(\textcolor{stringliteral}{"TEST"}, \textcolor{stringliteral}{"TEST"}, 5);
00071     printf(\textcolor{stringliteral}{"%i"}, DirectoryExists(\textcolor{stringliteral}{"TEST"}));
00072     DeleteFile(\textcolor{stringliteral}{"TEST"});
00073 \}
00074 \textcolor{preprocessor}{#endif }\textcolor{comment}{/* TEST */}
\end{alltt}\end{footnotesize}
